package exemple.DesignExample.repository;

import exemple.DesignExample.dao.Dao;
import exemple.DesignExample.model.Entity;
import java.util.Collections;
import java.util.List;

public class RepositoryDao<TYPE extends Entity> implements Dao<TYPE> {

    public RepositoryDao() {}
    
    @Override
    public final void insert( TYPE entity ) {
        this.preInsert(entity);
        this.preStore(entity);

        //Insert Entity

        this.postStore(entity);
        this.postInsert(entity);
    }

    @Override
    public final void update( TYPE entity ) {
        this.preUpdate(entity);
        this.preStore(entity);

        //Update Entity

        this.postStore(entity);
        this.postUpdate(entity);
    }

    @Override
    public final TYPE findById( Entity entityId ) {
        //Select by Id
        TYPE resultEntity = null;

        this.postLoad(resultEntity);
        return resultEntity;
    }

    @Override
    public final List< TYPE > findAll() {
        //Seelct all
        List<TYPE> resultEntities = Collections.EMPTY_LIST;

        this.postLoadList(resultEntities);
        return resultEntities;
    }

    /** Hook Methods **/
    public void preInsert(TYPE entity) {}
    public void postInsert(TYPE entity) {}
    public void preUpdate(TYPE entity) {}
    public void postUpdate(TYPE entity) {}
    public void preStore(TYPE entity) {}
    public void postStore(TYPE entity) {}
    public void postLoad(TYPE entity) {}
    public void postLoadList(List<TYPE> entities) {}
}
